Jak zapisovat a cist COM1 ve Win2K/XP

Otázka od: Robert Plzak

22. 9. 2004 11:12

Zdravim odborniky,

mate nekdo zkusenosti s primym pristupem na ComPort
z Delphi aplikace? Potreboval bych posilat a cist
stav z portu. Zkousel jsem TApdComPort od TurboPower
ale neumim to  

Pomuzete poradite  

     Robert Plzak



Odpovedá: PcolaS

22. 9. 2004 12:20

Mne funguje nasledovne v D5.


uses Windows,SysUtils ;

..
..
  Case CisloCom of
1:ComStr:='COM1';2:ComStr:='COM2';3:ComStr:='COM3';4:ComStr:='COM4';

5:ComStr:='COM5';6:ComStr:='COM6';7:ComStr:='COM7';8:ComStr:='COM8';
                  9:ComStr:='COM9';
               else begin InicialCom:=co_U1_IniCom_ErrCisCom; Exit; end;end;

ComId:=CreateFile(PChar(ComStr),GENERIC_WRITE+GENERIC_READ,0,nil,OPEN_EXISTI
NG,FILE_ATTRIBUTE_NORMAL,0);
  if ComId = INVALID_HANDLE_VALUE then begin
InicialCom:=co_U1_IniCom_ErrOpen; exit; end;


if SetCom(ComId)<>0 then begin InicialCom:=co_U1_IniCom_ErrSetCom ;exit;end;
{funkcia inicializujuca COM}


Function SetCom(C:THandle): Integer; {nastavi konfig COMu }
var
    locDCB :TDCB;
    ComConfSP : PCommConfig;
    size : DWORD;
  begin
  SetComUst:=0;
  size := sizeof(TCommConfig);
  GetMem(ComConfSP,size);
  if NOT GetCommConfig(C,ComConfSP^,size) then begin
SetCom:=-1;FreeMem(ComConfSP,size);exit;end;
  ComConfSP^.dcb.BaudRate:=CBR_9600;
  ComConfSP^.dcb.ByteSize:=8;
  ComConfSP^.dcb.StopBits:=OneSTOPBit;
  ComConfSP^.dcb.Parity:=NOParity;
  ComConfSP^.dcb.Flags := fBinary;
  if NOT SetCommConfig(C,ComConfSP^,size) then begin
SetCom:=-1;FreeMem(ComConfSP,size);exit;end;
  if NOT PurgeComm
(C,(PURGE_TXABORT+PURGE_RXABORT+PURGE_TXCLEAR+PURGE_RXCLEAR))then begin
SetComUst:=-1;FreeMem(ComConfSP,size);exit;end;{vyprazdnime vysielaci
buffer}
  FreeMem(ComConfSP,size);
  end; { Function SetCom(C:THandle): Integer; }


        ReadFile(COMId,InU2ZU1[PocetByteVInU2ZU1],PocRead
,DWORD(PocetByteVInU2ZU1),nil);{Nacitame prisle Byte a odovzdame ich U2}
      WriteFile(COMId,OutU2DoU1[0],PocetByteVOutU2DoU1,PocWrite,nil)
{Vyslanie byte}


----- Original Message -----
From: "Robert Plzak" <rpvp@vagnerplast.cz>
To: <delphi-l@clexpert.cz>
Sent: Wednesday, September 22, 2004 11:42 AM
Subject: Jak zapisovat a cist COM1 ve Win2K/XP


> Zdravim odborniky,
>
> mate nekdo zkusenosti s primym pristupem na ComPort
> z Delphi aplikace? Potreboval bych posilat a cist
> stav z portu. Zkousel jsem TApdComPort od TurboPower
> ale neumim to  
>
> Pomuzete poradite  
>
> Robert Plzak
>
>
>